package com.wy.multilevelpulldown;

import android.database.DataSetObservable;
import android.database.DataSetObserver;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

/**
 * Time:8/31/21
 * Author:ypf
 * Description:
 */
public abstract class MenuBaseAdapter {


    private final DataSetObservable mDataSetObservable = new DataSetObservable();

    /**
     * 关闭菜单:用于改变tabView显示状态
     *
     * @param tabView
     */
    public abstract void overrideCloseMenu(View tabView);

    /**
     * 打开菜单：用于改变tabView显示状态
     */
    public abstract void overrideOpenMenu(View tabView,
                                          int position);

    /**
     * 得到多少条
     */
    public abstract int getCount();

    /**
     * 得到Menu的内容
     */
    public abstract View getMenuView(int position,
                                     FrameLayout menuContainerView,
                                     ListPopuScreenMenuView parent);

    /**
     * 得到Table的内容
     */
    public abstract View getTabView(int position,
                                    LinearLayout tabContainerView,
                                    ListPopuScreenMenuView parent);

    /**
     * 关闭筛选菜单菜单
     */
    public void closeScreenMenu() {
        mDataSetObservable.notifyChanged();
    }

    public void registerDataSetObserver(DataSetObserver observer) {
        mDataSetObservable.registerObserver(observer);
    }

    public void unregisterDataSetObserver(DataSetObserver observer) {
        mDataSetObservable.unregisterObserver(observer);
    }

    /**
     * Notifies the attached observers that the underlying data has been changed
     * and any View reflecting the data set should refresh itself.
     */
    public void notifyDataSetChanged() {
        mDataSetObservable.notifyChanged();
    }

    //微信公众号 注册订阅用户就放入了集合
    private MenuObserver mMenuObserver;

    public void registerDataSetObserver(MenuObserver observer) {
        mMenuObserver = observer;
    }

    public void unregisterDataSetObserver(MenuObserver observer) {
        mMenuObserver = null;
    }

    /**
     * Notifies the attached observers that the underlying data has been changed
     * and any View reflecting the data set should refresh itself.
     */
    public void notifyCloseMenu() {
        if (mMenuObserver != null)
            mMenuObserver.closeMenu();
    }

}